using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class GonerMenu_Settings : MonoBehaviour
{
	public enum CurrentSettingsMenuState
	{
		NoTabSelected,
		TabSelected,
		OptionSelected
	}

	public enum SettingsMenuTabs
	{
		GAME,
		AUDIO,
		CONTROLS,
		ACCESSIBILITY
	}

	public bool SettingsMenuOpen;

	[Header("-= Main =-")]
	public CurrentSettingsMenuState CurrentMenuState;

	public SettingsMenuTabs CurrentSelectedTab;

	[Header("-= References =-")]
	[SerializeField]
	private SettingsMenuTab[] SelectableTabs;

	[SerializeField]
	private RectTransform Soul;

	[SerializeField]
	private GonerMenu_SettingsSection[] SettingSections;

	[SerializeField]
	private GonerMenu GonerMenu;

	[SerializeField]
	private GameObject NewMainMenu_ConsoleMenu;

	[SerializeField]
	private GameObject NewMainMenu_SettingsParentGameobject;

	[Header("Description")]
	[SerializeField]
	private TextMeshProUGUI CurrentSelectedTitle;

	[SerializeField]
	private TextMeshProUGUI CurrentSelectedDescription;

	[Header("-= Sounds =-")]
	public AudioSource source;

	public AudioClip SettingSound_Move;

	public AudioClip SettingSound_Select;

	public AudioClip SettingSound_Tick;

	public AudioClip SettingSound_Blip;

	public AudioClip SettingSound_BackOut;

	public AudioClip SettingSound_Explosion;

	[Header("-= Dyslexic Font Setup -=")]
	[SerializeField]
	private List<TextMeshProUGUI> FontsAffectedByDyslexic = new List<TextMeshProUGUI>();

	[SerializeField]
	private TMP_FontAsset defaultFont;

	[SerializeField]
	private TMP_FontAsset dyslexicFont;

	private int CurrentTabSelected;

	private int CurrentSettingSelected;

	private bool hasUpdatedFontsDyslexic;

	private GonerMenu_SettingsSection CurrentSection;

	private static GonerMenu_Settings instance;

	public static GonerMenu_Settings Instance => instance;

	private void Awake()
	{
		if ((Object)(object)GonerMenu != (Object)null)
		{
			if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				instance = this;
			}
		}
	}

	private void Update()
	{
		if (SettingsMenuOpen)
		{
			if (CurrentMenuState == CurrentSettingsMenuState.NoTabSelected)
			{
				NoTabSelectedUpdate();
			}
			else if (CurrentMenuState == CurrentSettingsMenuState.TabSelected)
			{
				TabSelectedUpdate();
			}
			else
			{
				OptionSelectedUpdate();
			}
			if (!hasUpdatedFontsDyslexic)
			{
				hasUpdatedFontsDyslexic = true;
				UpdateSettingFontsDyslexic();
			}
		}
		else
		{
			hasUpdatedFontsDyslexic = false;
			SettingsMenuOffUdpate();
		}
		if (!GonerMenu.Instance.GonerMenuOpen && (Object)(object)GonerMenu != (Object)null)
		{
			SettingsMenuOpen = false;
			CurrentMenuState = CurrentSettingsMenuState.NoTabSelected;
		}
		if ((Object)(object)GonerMenu == (Object)null)
		{
			SettingsMenuOpen = true;
		}
	}

	private void SettingsMenuOffUdpate()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < SelectableTabs.Length; i++)
		{
			((Graphic)SelectableTabs[i].TabBackground).color = Color.white;
			((Graphic)SelectableTabs[i].TabIcon).color = Color.white;
			((Graphic)SelectableTabs[i].TabText).color = Color.white;
			SelectableTabs[i].Tabs_TargetSize = 0.95f;
		}
	}

	private void NoTabSelectedUpdate()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Left))
		{
			CurrentTabSelected--;
			source.PlayOneShot(SettingSound_Move);
			CurrentSettingSelected = 0;
		}
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Right))
		{
			CurrentTabSelected++;
			source.PlayOneShot(SettingSound_Move);
			CurrentSettingSelected = 0;
		}
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Confirm))
		{
			source.PlayOneShot(SettingSound_Select);
			OpenSettingsTab(SelectableTabs[CurrentTabSelected].TabToOpen);
		}
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Down))
		{
			source.PlayOneShot(SettingSound_Move);
			CurrentSettingSelected = 0;
			OpenSettingsTab(SelectableTabs[CurrentTabSelected].TabToOpen);
		}
		if (CurrentTabSelected < 0)
		{
			CurrentTabSelected = SelectableTabs.Length - 1;
		}
		if (CurrentTabSelected > SelectableTabs.Length - 1)
		{
			CurrentTabSelected = 0;
		}
		GonerMenu_SettingsSection[] settingSections = SettingSections;
		for (int i = 0; i < settingSections.Length; i++)
		{
			((Component)settingSections[i]).gameObject.SetActive(false);
		}
		((Component)SettingSections[CurrentTabSelected]).gameObject.SetActive(true);
		for (int j = 0; j < SelectableTabs.Length; j++)
		{
			((Graphic)SelectableTabs[j].TabBackground).color = Color.white;
			((Graphic)SelectableTabs[j].TabIcon).color = Color.white;
			((Graphic)SelectableTabs[j].TabText).color = Color.white;
			SelectableTabs[j].Tabs_TargetSize = 0.95f;
			SelectableTabs[CurrentTabSelected].Tabs_TargetSize = 1.3f;
			if ((Object)(object)GonerMenu != (Object)null)
			{
				SelectableTabs[j].Tab.transform.localScale = Vector3.Lerp(SelectableTabs[j].Tab.transform.localScale, Vector3.one * SelectableTabs[j].Tabs_TargetSize, 15f * Time.unscaledDeltaTime);
			}
			((Graphic)SelectableTabs[CurrentTabSelected].TabBackground).color = Color.yellow;
			((Graphic)SelectableTabs[CurrentTabSelected].TabIcon).color = Color.yellow;
			((Graphic)SelectableTabs[CurrentTabSelected].TabText).color = Color.yellow;
		}
		if ((Object)(object)GonerMenu != (Object)null)
		{
			GonerMenu.TargetSoulPosition = new Vector2(-1995f, GonerMenu.TargetSoulPosition.y);
		}
		else
		{
			((Transform)Soul).position = Vector2.op_Implicit(new Vector2(-1935f, 5000f));
		}
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Cancel))
		{
			if ((Object)(object)GonerMenu != (Object)null)
			{
				SettingsMenuOpen = false;
				GonerMenu.CurrentMenuState = "Default";
				GonerMenu.CurrentCursorPosition = 1;
				GonerMenu.GonerMenuSource.PlayOneShot(SettingSound_BackOut);
			}
			else
			{
				SettingsMenuOpen = false;
				NewMainMenuManager.instance.MenuSource.PlayOneShot(SettingSound_BackOut);
				NewMainMenu_SettingsParentGameobject.SetActive(false);
				NewMainMenu_ConsoleMenu.SetActive(true);
			}
		}
	}

	private void TabSelectedUpdate()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_030d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < SelectableTabs.Length; i++)
		{
			((Graphic)SelectableTabs[i].TabBackground).color = Color.grey;
			((Graphic)SelectableTabs[i].TabIcon).color = Color.grey;
			((Graphic)SelectableTabs[i].TabText).color = Color.grey;
			SelectableTabs[i].Tabs_TargetSize = 0.7f;
			SelectableTabs[CurrentTabSelected].Tabs_TargetSize = 1f;
			if ((Object)(object)GonerMenu != (Object)null)
			{
				SelectableTabs[i].Tab.transform.localScale = Vector3.Lerp(SelectableTabs[i].Tab.transform.localScale, Vector3.one * SelectableTabs[i].Tabs_TargetSize, 15f * Time.unscaledDeltaTime);
			}
			((Graphic)SelectableTabs[CurrentTabSelected].TabBackground).color = Color.yellow;
			((Graphic)SelectableTabs[CurrentTabSelected].TabIcon).color = Color.yellow;
			((Graphic)SelectableTabs[CurrentTabSelected].TabText).color = Color.yellow;
		}
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Up))
		{
			CurrentSettingSelected--;
			source.PlayOneShot(SettingSound_Move);
		}
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Down))
		{
			CurrentSettingSelected++;
			source.PlayOneShot(SettingSound_Move);
		}
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Confirm))
		{
			CurrentSection.Settings[CurrentSettingSelected].CurrentlySelected = true;
			CurrentMenuState = CurrentSettingsMenuState.OptionSelected;
			source.PlayOneShot(SettingSound_Select);
		}
		if (CurrentSettingSelected < 0)
		{
			CurrentSettingSelected = CurrentSection.Settings.Length - 1;
		}
		if (CurrentSettingSelected > CurrentSection.Settings.Length - 1)
		{
			CurrentSettingSelected = 0;
		}
		if ((Object)(object)CurrentSection != (Object)null)
		{
			((TMP_Text)CurrentSelectedTitle).text = CurrentSection.Settings[CurrentSettingSelected].SettingsElementName;
			((TMP_Text)CurrentSelectedDescription).text = CurrentSection.Settings[CurrentSettingSelected].SettingsDescription;
		}
		if ((Object)(object)GonerMenu != (Object)null)
		{
			GonerMenu.TargetSoulPosition = new Vector2(-550f, ((Component)CurrentSection.Settings[CurrentSettingSelected]).transform.localPosition.y - 126.5f);
		}
		else
		{
			((Transform)Soul).localPosition = Vector2.op_Implicit(new Vector2(-550f * ((Component)this).transform.localScale.x, (((Component)CurrentSection.Settings[CurrentSettingSelected]).transform.localPosition.y - 126.5f) * ((Component)this).transform.localScale.x));
		}
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Cancel))
		{
			CurrentMenuState = CurrentSettingsMenuState.NoTabSelected;
			CurrentSection = null;
			((TMP_Text)CurrentSelectedTitle).text = "";
			((TMP_Text)CurrentSelectedDescription).text = "";
			source.PlayOneShot(SettingSound_BackOut);
		}
	}

	private void OptionSelectedUpdate()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(PlayerInput.Instance.Key_Cancel) && CurrentSection.Settings[CurrentSettingSelected].CanBeCanceled)
		{
			CurrentSection.Settings[CurrentSettingSelected].CurrentlySelected = false;
			CurrentMenuState = CurrentSettingsMenuState.TabSelected;
			source.PlayOneShot(SettingSound_BackOut);
		}
	}

	public void CancelOutOfCurrentSetting()
	{
		CurrentSection.Settings[CurrentSettingSelected].CurrentlySelected = false;
		CurrentMenuState = CurrentSettingsMenuState.TabSelected;
		source.PlayOneShot(SettingSound_BackOut);
	}

	private void OpenSettingsTab(SettingsMenuTabs tab)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		CurrentSelectedTab = tab;
		CurrentMenuState = CurrentSettingsMenuState.TabSelected;
		GonerMenu_SettingsSection[] settingSections = SettingSections;
		foreach (GonerMenu_SettingsSection gonerMenu_SettingsSection in settingSections)
		{
			if (gonerMenu_SettingsSection.ThisAssosciatedTab == CurrentSelectedTab)
			{
				CurrentSection = gonerMenu_SettingsSection;
			}
		}
		((Transform)Soul).localPosition = Vector2.op_Implicit(new Vector2(-760f, 200f));
	}

	public void UpdateSettingFontsDyslexic()
	{
		bool boolSettingValue = SettingsManager.Instance.GetBoolSettingValue("DyslexicText");
		foreach (TextMeshProUGUI item in FontsAffectedByDyslexic)
		{
			if (boolSettingValue)
			{
				((TMP_Text)item).font = dyslexicFont;
			}
			else
			{
				((TMP_Text)item).font = defaultFont;
			}
		}
	}
}
